package com.chen.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 向三大域中放入数据
        // 向请求域中放入数据
        req.setAttribute("req", "reqMsg");

        // 向session域中放入数据
        HttpSession session = req.getSession();
        session.setAttribute("session", "sessionMsg");

        // 向应用域中放入数据
        ServletContext application = getServletContext();
        application.setAttribute("application", "applicationMsg");


        // 获取请求域中数据
        System.out.println(req.getAttribute("req"));


        //设置请求转发
        req.getRequestDispatcher("/servletB").forward(req, resp);


    }
}
